package com.vcredit.creditcat.web;

import com.sun.net.httpserver.Authenticator.Success;
import com.vcredit.creditcat.framework.pagination.Page;
import com.vcredit.creditcat.model.AppCondition;
import com.vcredit.creditcat.model.AppVersion;
import com.vcredit.creditcat.model.Banner;
import com.vcredit.creditcat.model.MerchantProduct;
import com.vcredit.creditcat.model.ProcessSpecial;
import com.vcredit.creditcat.model.ProcessSpecialCondition;
import com.vcredit.creditcat.service.AppConditionService;
import com.vcredit.creditcat.service.AppVersionService;
import com.vcredit.creditcat.service.BannerService;
import com.vcredit.creditcat.service.MerchantProductService;
import com.vcredit.creditcat.service.ProcessSpecialConditionService;
import com.vcredit.creditcat.service.ProcessSpecialService;
import com.vcredit.creditcat.service.ProductConditionService;
import com.vcredit.creditcat.vo.AppConditionParamVo;
import com.vcredit.creditcat.vo.AppConditionVo;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.cxf.annotations.UseAsyncMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/*
 * @author zhangxingong
 * @version 1.0
 * @since 1.0
*/
@RestController
@RequestMapping("/appCondition")
public class AppConditionController extends BaseController {

  @Autowired
  private AppConditionService appConditionService;
  @Autowired
  private AppVersionService appVersionService;
  @Autowired
  private BannerService bannerService;
  @Autowired
  private MerchantProductService merchantProductService;
  @Autowired
  private ProcessSpecialService processSpecialService;

  @RequestMapping(value = "/list")
  public ModelAndView showPageAppCondition(HttpServletRequest request) {
    return new ModelAndView("appcondition/appConditionList");
  }

  @RequestMapping(value = "/listAppCondition", method = RequestMethod.GET)
  public Page<AppCondition> findByPageAppCondition(HttpServletRequest request) {
    return appConditionService.findByPage(makeDefaultCriteria(request));
  }

  @RequestMapping(value = "/findAllVersion")
  public Page<AppVersion> findAllAppVersion(HttpServletRequest request) {
    return appVersionService.findByPage(makeDefaultCriteria(request));
  }

  @RequestMapping(value = "/findAllBanner")
  public Page<Banner> findAllBanner(HttpServletRequest request) {
    return bannerService.findByPage(makeDefaultCriteria(request));
  }

  @RequestMapping("/findAllProduct")
  public Page<MerchantProduct> findAllProduct(HttpServletRequest request) {
    return merchantProductService.findByPage(makeDefaultCriteria(request));
  }

  @RequestMapping(value = "/findAllSpecialProduct")
  public Page<ProcessSpecial> findAllSpecialProduct(HttpServletRequest request) {
    return processSpecialService.findByPage(makeDefaultCriteria(request));
  }

  @RequestMapping(value = "/saveAppCondition", method = RequestMethod.POST)
  public String saveAppCondition(@RequestBody AppConditionVo appConditionVo,
      HttpServletRequest request) {
      appConditionService.save(appConditionVo);
    return SUCCESS;
  }

  @RequestMapping(value = "/batchInsertAppConditon", method = RequestMethod.POST)
  public String batchInsertAppConditon(@RequestBody AppConditionParamVo paramVo, HttpServletRequest request) {
     appConditionService.batchInsert(paramVo);
    return SUCCESS;
  }

  @RequestMapping(value = "/updateAppCondition", method = RequestMethod.PUT)
  public String updateAppCondition(@RequestBody AppCondition appCondition,
      HttpServletRequest request) {
      appConditionService.update(appCondition);
    return SUCCESS;
  }

  @RequestMapping(value = "/removeAppCondition", method = RequestMethod.DELETE)
  public String removeAppCondition(@RequestParam("ids") String ids, HttpServletRequest request) {
      appConditionService.removeAppCondition(ids);
    return SUCCESS;
  }
}
